<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>欢迎登录</title>
    <link rel="stylesheet" type="text/css" href="css/login.css" />
</head>

<body>
    <div class="header">
        <div class="container">
            <div class="header-yi">
                <div class="header-logo" style="margin-top: 20px;">
                    <a href="index.html"><img src="imges/logo.png"></a>
                </div>
                <p class="header-text">欢迎登录</p>
            </div>
        </div>
    </div>
    <div class="body">
        <div class="body-form">
            <h1 class="body-form-t">账户登录</h1>
            <div class="body-input">
                <span class="iconfont icon-yonghu"></span>
                <input type="text" placeholder="请输入账号" class="zhang">
            </div>
            <div class="body-input">
                <span class="iconfont icon-lock-fill"></span>
                <input type="password" placeholder="请输入密码" class="mima">
            </div>
            <div class="body-wj">
                <a href="#">忘记密码</a>
            </div>
            <div class="body-btn">
                <button class="OK">登录</button>
            </div>
            <div class="body-zc">
                <a href="register.html"><span class="iconfont icon-you"></span><span>立即注册</span></a>
            </div>
        </div>
    </div>
    <div class="foot">
        © 2022 All Rights Reserved.
    </div>
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
        $(function() {
            var zcuser;
            if (sessionStorage.getItem("zcuser") != "") {
                zcuser = JSON.parse(sessionStorage.getItem("zcuser"));
            }
            if (zcuser != null) {
                $('.zhang').val(zcuser.name);
                $('.mima').val(zcuser.password);
                sessionStorage.removeItem("zcuser");
            }
            $('.OK').click(function() {
                if ($('.zhang').val() != '' || $('.mima').val() != '') {
                    $.ajax({
                        url: 'http://localhost:2380/api/UserKong/dengru',
                        data: {
                            name: $('.zhang').val(),
                            password: $('.mima').val()
                        },
                        type: 'get',
                        datatype: 'json',
                        success: function(dt) {
                            if (dt != false) {
                                alert('登陆成功！');
                                sessionStorage.setItem("user", JSON.stringify(dt))
                                location.href = 'index.html';
                            } else {
                                alert('登入失败！，请检查账号或密码是否填写正确！');
                                console.log(dt);
                            }
                        }
                    })
                } else {
                    alert('文本框不能为空！');
                }
            })
        })
    </script>
</body>

</html>